﻿Imports System.Web.Script.Serialization

Public Class JosJsonParser(Of T As JosResponse)
    Implements IJosParser(Of T)

    Public Function Parse(ByVal body As String) As T Implements IJosParser(Of T).Parse
        Dim serializer As New JavaScriptSerializer
        Dim rsp As T = Nothing
        rsp = serializer.Deserialize(Of T)(body)
        If rsp Is Nothing Then
            rsp = Activator.CreateInstance(Of T)()
        End If
        rsp.Body = body
        Return rsp
    End Function

    Public Shared Function JsonSerializer(Of K)(ByVal req As K) As String
        Dim serializer As New JavaScriptSerializer 
        Return serializer.Serialize(req)
    End Function

End Class
